home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / Drag_on Modules / hAWK programs / $ExpandAssertions < prev    next >
Encoding:
Text File  |  1993-04-09  |  1.1 KB  |  29 lines  |  [TEXT/KEEN]

  1. # $ExpandAssertions : see "Debugging hAWK programs"
  2. # "Go to": see «Debugging hAWK programs» «b  1   Assertions»
  3. # (the tricky bits - treat quotes properly, and
  4. # avoid using sub(), since the replacement string might contain
  5. # a "&" which stands for "everything that was matched".)
  6. #
  7. # Pass it your problem program as the single input file:
  8. # overwrites the file, replacing         a(assertion)          with
  9. #         assert(assertion, "assertion", line number) ###
  10. FNR == 1 {outfile = FILENAME}
  11.  {    if (match($0, /[ \t]*a\((.+)\)/))
  12.         {
  13.         match($0, /\((.+)\)/) #find the argument proper
  14.         first = substr($0, RSTART+1, RLENGTH-2) #copy it
  15.         second = first
  16.         gsub(/"/, "\\\"", second) #escape quotes
  17.         match($0, /[ \t]*/) #match starting white space
  18.         starter = substr($0, RSTART, RLENGTH) #copy it
  19.         $0 = starter "assert(" first ", \"" second "\", " FNR ") ###"
  20.         ##sub(/a\((.+)\)/, "assert(" first ", \"" second "\", " FNR ") ###")
  21.         ##-deleted, doesn't work properly if "second" contains a "&"
  22.         }
  23.     out[++i] = $0
  24.  }
  25. END {    close(outfile)
  26.         for (j = 1; j <= i; ++j)
  27.             print out[j] > outfile
  28.     }
  29.